package com.promise.paging

import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import android.arch.lifecycle.ViewModelProviders
import android.support.v4.app.FragmentActivity

/**
 * Created by CQNNJ-003 on 2018/6/7.
 */
class ViewModelHelper {

    private fun getViewModel(fa: FragmentActivity): ViewModel {
        return ViewModelProviders.of(fa, object : ViewModelProvider.Factory {
            override fun <T : ViewModel?> create(modelClass: Class<T>): T {
                val repo = ServiceLocator.instance()
                        .getRepository()
                @Suppress("UNCHECKED_CAST")
                return UserViewModel(repo as UserPostRepository) as T
            }
        })[ViewModel::class.java]
    }
}